// pages/index/fm/fm.js
Page({

  /**
   * Page initial data
   */
  data: {
    fmTableData:[],
    currentPage:1,
    pageSize:17,
    loading:false,
    hasMoreData:true
  },

  transDetail(e){
    wx.navigateTo({
      url: `/pages/index/fm/fmdetail/FmDetail?id=${e.currentTarget.dataset.id}`,
    })
  },
  loadData(){
    this.setData({
      currentPage:this.data.currentPage + 1,
      loading:true
    });
    if (!this.data.hasMoreData) {
      return;
    }
    wx.request({
      url: `http://localhost:8080/fm/fmlist?pageNum=${this.data.currentPage}&pageSize=${this.data.pageSize}`,
      success:(res) => {
       
        if (res.data.list.length > 0) {
          this.setData({
            fmTableData:[...this.data.fmTableData,...res.data.list]
          })
        } else {
          this.setData({
            hasMoreData:false
          })
        }
      },complete:() => {
        this.setData({
          loading:false
        })
      }
    })
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad(options) {

  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady() {
    wx.request({
      url: `http://localhost:8080/fm/fmlist?pageNum=${this.data.currentPage}&pageSize=${this.data.pageSize}`,
      success:(res) => {
        this.setData({
          fmTableData:res.data.list
        })
      }
    })
  },
  onReachBottom(){
    console.log("hello2");
    this.loadData();
  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow() {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide() {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload() {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh() {

  },



  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage() {

  }
})